-
Notifications
You must be signed in to change notification settings - Fork 3.4k
add a guide how to declare plugin typings #1042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM!
src/v2/guide/typescript.md
Outdated
|
||
## Declaring Types of Vue Plugins | ||
|
||
Plugins may augment Vue's global/instance properties, component options and so on. For that case, augmenting type declaration is also needed to use plugins in TypeScript. Fortunately, there is a feature to augment an existing types that is called [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
augment
appears three times in this paragraph, which reads quite wordy. Also augment
is rather an abstract term, so it is quite hard for TypeScript new comers.
I would suggest change some verbs:
Plugins may add Vue's global/instance properties, component options and so on. For that case, type declaration also needs updates to make plugins code compile in TypeScript.
add
and update
explains what augment
does before we introduce the TS feature. I think this should be clearer for ordinary Vue users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion 👍 Updated!
@ktsn Looks great! I just made some small tweaks to the wording. |
* add a guide how to declare plugin typings (vuejs#1042) * add a guide how to declare plugin typings * improve wording * Slight tweak to working for declaring typescript types for plugins * Translate declaring types of vue plugins * Update the updated field in ts guide
I'm seeing some users struggling how to declare typings for plugins (e.g. vuejs/vue-class-component#128), especially the plugin that augments instance property/component options. I think it can be tricky because we have to use a feature that most of ts users may not know.
This PR adds an example code to do that. I think it would be helpful not only for plugin developers but also users that uses a plugin not include typings since they can know how to make it by themselves.